﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using WinTest.GpSpotMe.Ign.TileModel;
using Microsoft.WindowsMobile.Samples.Location;

namespace GpSpotMe
{
    public partial class MapPanel : UserControl
    {
        private GpsPosition p;
        private IgnMap map;

        public MapPanel()
        {
            InitializeComponent();
        }

        public GpsPosition Position
        {
            get { return p; }
            set { p = value; }
        }

        public void SpotMe()
        {
            if (p != null && p.LatitudeValid && p.LongitudeValid)
            {
                double easting, northing;
                int zone;
                GeoTrans.Converter.PolarWGS84ToUTMinED50(p.Latitude, p.Longitude, 0, out easting, out northing, out zone);

                //TODO: De momento asume que estamos en el huso 30
                Point utmP = new Point((int)easting, (int)northing);
                map = new IgnMap(utmP, 200, 2);
                this.Invalidate();
            }
        }

        private void MapPanel_Paint(object sender, PaintEventArgs e)
        {
           if(map != null) e.Graphics.DrawImage(map.Bmp, 0, 0);
        }
    }
}
